<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">旅游产品<small>商品供应商商品类别列表</small></h3>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-search"></i>搜索</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal form-search" action="<?php echo base_url('tourismprovidercategory/grid') ?>" method="get">
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">供应商</label>
                                    <div class="controls">
                                        <input type="text" name="uid" value="<?php echo $this->input->get('uid');?>" class="m-wrap span10" placeholder="请输入供应商UID">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">上下架</label>
                                    <div class="controls">
                                        <select name="is_on_sale" class="m-wrap span10">
                                            <option value="">请选择</option>
                                            <option value="1" <?php if($this->input->get('is_on_sale')==1){echo 'selected';}?> >上架</option>
                                            <option value="2" <?php if($this->input->get('is_on_sale')==2){echo 'selected';}?>>下架</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit">搜索</button>
                            <button class="btn reset_button_search" type="button">重置条件</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>列表</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="dataTables_wrapper form-inline">
                        <div class="row-fluid scebery-order-pagination">
                            <span class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now;?></span>页 
                                <span>共</span><span style="color: red"><?php echo $all_rows;?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_list; ?>
                            </span>
                            <span class="scebery-order-find">
                                <input type="text" name="pg" value="<?php echo isset($pg_now) ? $pg_now :'';?>" class="m-wrap small" placeholder="请输入页数" />
                                <button type="button" class="btn green">确定</button>
                                <button type="button" class="btn green" onclick="window.location.href=localtion.href">刷新</button>
                                <a type="button" class="btn red" href="<?php echo base_url('tourismprovidercategory/add?uid='.$this->input->get('uid')) ?>">添加</a>
                                <a type="button" class="btn yellow up" flag="1" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">上架</a>
                                <a type="button" class="btn yellow down" flag="2" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">下架</a>
                            </span>
                        </div>
                        <?php if ($page_list->num_rows()>0) :?>
                        <table class="table table-striped table-bordered table-hover" id="sample_1">
                            <thead class="flip-content">
                                <tr>
                                    <th width="15"><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"></th>
                                    <th>供应商UID/名称</th>
                                    <th>名称</th>
                                    <th>排序</th>
                                    <th>主推类</th>
                                    <th>创建时间</th>
                                    <th>上下架</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($page_list->result() as $item): ?>
                                <tr>
                                    <th><input type="checkbox" class="checkboxes provider-category" value="<?php echo $item->id;?>" /></th>
                                    <td><?php echo $item->provider_uid.'/'.$item->user_name; ?></td>
                                    <td><?php echo $item->category_name?></td>
                                    <td><?php echo $item->sort;?></td>
                                    <td><?php echo ( $item->is_main == 2 ) ? '是':'否';?></td>
                                    <td><?php echo $item->creat_at;?></td>
                                    <td>
                                        <a href="javascript:;" class="modify-user-uid glyphicons no-js <?php if ($item->is_on_sale == 1):?>ok_2<?php else :?>remove_2<?php endif;?>" data-id="<?php echo $item->id;?>" data-flag="<?php echo $item->is_on_sale; ?>" data-is-main="<?php echo $item->is_main;?>">
                                            <i></i>
                                        </a>
                                    </td>
                                    <td width="100">
                                        <a class="btn mini green" href="<?php echo base_url('tourismprovidercategory/edit/'.$item->id) ?>">编辑</a>
                                        <a class="btn mini green" href="<?php echo base_url('tourismprovidercategory/delete/'.$item->id.'/'.$item->is_main) ?>">删除</a>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                        <div class="row-fluid">
                            <div class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now ?></span>页
                                <span>共</span><span style="color: red"><?php echo $all_rows ?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_list ?>
                            </div>
                        </div>
                        <?php else : ?>
                            <div class="alert"><p>未找到数据。<p></div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(function(){
    
	$('.scebery-order-find  button').click(function(){
		var pg = $(this).parents('.scebery-order-find').find('input[name="pg"]').val();
		if (pg.length==0) {
		    return false;
		}
		window.location.href="<?php echo base_url('tourismprovidercategory/grid')?>"+"/"+pg+"<?php echo isset($url) ? $url :'';?>";
	})
	
	$('.scebery-order-find').delegate('.up,.down','click',function(e){

  	   var id = [];
	   var type = $(this).attr('flag');
	   var pg = $(this).attr('pg');
	   var _this = $(this);
       $('.provider-category:checked').each(function(i){
      	   id[i] = $(this).val();
       })
       if (id.length==0) {
   	       return alert('请选择分类序列号');
       }
       $.ajax({
    	   type: 'post',
           async: true,
           dataType: 'json',
           url: hostUrl() + '/tourismprovidercategory/batchIsOnSale',
           data: {type:type,pg:pg,id:id},
           beforeSend:function(){
        	   _this.text('操作中').attr("disabled",true);
           },
           success: function (data) {
               if (data.status) {
                   $('.alert-error').hide();
                   window.location.href = data.messages;
               } else {
                   $('.alert-error').show();
                   $('.alert-error .remove_2 p').html(data.messages);
                   var body = (window.opera) ? (document.compatMode == 'CSS1Compat' ? $('html') : $('body')) : $('html,body');
                   body.animate({scrollTop: $('.page-container').offset().top}, 1000);
                   _this.text('请重新操作').attr("disabled",false);
               }
           }
       })
    })
    
    $('.modify-user-uid').click(function(){
        var status = '下架';
        if ($(this).hasClass('remove_2')) {
            status = '上架';
        }
        if (confirm('确定要'+status+'?')) {
            var obj = $(this);
            var id = obj.attr('data-id');
            var flag = obj.attr('data-flag');
            var is_main = obj.attr('data-is-main');
            if (is_main == 2 && flag == 1){
               alert('该类为供应商主推类，如果下架，就会导致前台数据不显示，请立即更换供应商主推类');
            }
            $.ajax({
                url:hostUrl()+'/tourismprovidercategory/toggle',
                type:'POST',
                dataType:'json',
                data: {id:id,flag:flag},
                success: function(data) {
                    if (data.flag == 2) {
                        obj.attr('data-flag', data.flag).addClass('remove_2').removeClass('ok_2');
                    } else if(data.flag == 1) {
                        obj.attr('data-flag', data.flag).addClass('ok_2').removeClass('remove_2');
                    } else {
                        alert('操作失败');
                    }
                }
            });
        }
    });
});
</script>